<?php
/**
 * Posts.php
 * 
 * @category    Madoqua
 * @package     Module
 * @subpackage  Install
 */

/** base class */
require_once 'Import/Source/Abstract.php';

require_once 'Blog/Post.php';


/**
 * Import_Source_Chyrp_Posts
 * 
 * @category    Madoqua
 * @package     Module
 * @subpackage  Install
 */
class Import_Source_Chyrp_Posts extends Import_Source_Abstract 
{
    protected $_name = 'posts';
    
    public function init()
    {
        $this->_targetTable = new Blog_Post();
    }
    
    public function import()
    {
        /**
         * Posts:
         * 
         * Chyrp      - Madoqua
         * --------------------
         * clean/url  - slug
         * xml->title - title
         * xml->body  - content
         * pinned     - NaN
         * status     - NaN
         * user_id    - NaN
         * created_at - posted
         * updated_at - NaN
         */
        $posts = $this->fetchAll($this->select());
        
        foreach ($posts as $post) {
        	$row  = $this->_targetTable->createRow();
        	
        	$xml  = new SimpleXMLElement($post->xml);
        	$date = new Zend_Date($post->created_at);
        	
        	$row->slug   = $post->clean;
        	$row->title  = $xml->post->title;
        	$row->intro  = $xml->post->body;
        	$row->posted = $date->toValue(Zend_Date::TIMESTAMP);
        	
        	$row->save();
        }
    }
}